********************************************************************************
*** NASTINESS IN GROUPS: REPLICATION FILES 
***Authors: Michal Bauer, Jana Cahlíková, Dagmara Celik Katreniak, Julie Chytilová, Lubomír Cingl, and Tomáš Želinský*
********************************************************************************

* Currently programmed for Stata 17
* For an earlier version, change number accordingly in the following:
version 17

* Version history
* Version 1: 31.10.2023 Jana Cahlikova

clear all
set more off
global date 200326
set seed 840801

/*
* installs lean2 scheme if not already installed
capture findfile lean2.scheme 	
if _rc==601 {
	net install gr0002_3, from(http://www.stata-journal.com/software/sj4-3)
	}
*/
set scheme lean2


** Set Directories *************************************************************

if "`c(username)'" == "cahj" { 
	global dropbox "/Users/cahj/Library/CloudStorage/Dropbox/Nasty groups/1_analysis/Nastiness_in_Groups_JEEA_replication" 
	}
	
/* Others: use the code snippet to set your working directory: need to change your username & path
if "`c(username)'" == "cahj" { 
	global dropbox "/Users/cahj/Dropbox/Nasty groups/1_analysis" 
	}
*/
	
*Important: for the code to work, you have to set up your main folder (path above) to have the following subfoders.
*All the data files should be saved in the "1_data" subfolder
*The Output subfolder should have two subfolders called "Tables" and "Figures" 	
global cleandatapath "$dropbox/1_data"
global dopath "$dropbox/2_do_files"
global outputpath "$dropbox/3_output"
global logpath "$dropbox/4_log"


** Datasets *************************************************************
	/*
	*All datasets are saved in the 1_clean_data folder
	*Experiment1.dta
	*Experiment2.dta
	*Experiment3.dta
	*Pilot_Experiment1.dta
	*Pilot_Experiment2.dta
	*Supplementary_Experiment.dta

	* 	Data also available as xml, produced by running "$dopath/04_codebook_data_export"
	*/


** Programs required ************************************************************

/*
* All programs that need to be installed to be listed here together with install command (ssc install xxx)
local required_ados "spmap shp2dta mif2dta distplot orth_out lincomest iebaltab" //add the required ados here// 
foreach x of local required_ados {
	capture findfile `x'.ado		
	if _rc==601 {
	ssc install `x'
	}
}
*/


** General options *************************************************************

* e.g., global / local lists of variables to be defined here


global esttab_opt_stats "stats(N, fmt(0) labels("Observations"))"
global cells "compress b(%3.2f) se(%3.2f) star(* 0.10 ** 0.05 *** 0.01) noomit nobase drop(`covars')"
global tex "collabels(,none)"
label define yes_no 0 "No" 1 "Yes"


** Run files *******************************************************************
* This part runs all do files from the data cleaning all the way to producing final output (figures and tables)


* 1. Tables in the main text (Table 1) and in the Appendix
do "$dopath/01_Tables_JEEA_final"
***see "$outputpath/Tables" for the resulting tables in an excel format (often separately by panel); note that some values are added manually to the Tables from the stata output (check the code for the respective table and the stata output)

* 2. Figures in the main text and in the Appendix
do "$dopath/02_Figures_JEEA_final"
***see "$outputpath/Figures" for the resulting Figures in a pdf (often separately by panel); note that some values (control means on the right) are added manually to the pdf from the stata output (check the code for the respective figure and the stata output)


* 3. Statistics mention in text in the manuscript
do "$dopath/03_Statistics_in_text_JEEA_final"
***check the code and the associated stata output 

**Estimated running time=29 seconds 
/*Last run on MacBook Pro with the following specifications:

  Model Name:	MacBook Pro
  Model Identifier:	MacBookPro18,3
  Chip:	Apple M1 Pro
  Total Number of Cores:	10 (8 performance and 2 efficiency)
  Memory:	16 GB
  STATA 17
  */



